package com.example.taximeter.controller;


import com.example.taximeter.bean.Privilege;
import com.example.taximeter.bean.User;
import com.example.taximeter.service.PrivilegeService;
import com.example.taximeter.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 权限
 */
@RestController
@RequestMapping(value = "/privilege")
public class PrivilegeController {

    private PrivilegeService privilegeService;
    private UserService userService;


    @Autowired
    public PrivilegeController(PrivilegeService privilegeService,UserService userService){
        this.privilegeService = privilegeService;
        this.userService = userService;
    }

    @RequestMapping(value = "/priv")
    public List<Privilege> findPrivList(){
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        User user1 = userService.findUserByUserid(user.getId());
        return privilegeService.findPrivinfoByRole(user1.getRoleid());
    }

    @RequestMapping(value = "/list")
    public List<Privilege> findPrivilegeList(){
        return privilegeService.findPrivilegelist();
    }
}
